package com.huidu.bitrade.controller;


import com.huidu.bitrade.constant.BipayTransterEnum;
import com.huidu.bitrade.dto.TransferParam;
import com.huidu.bitrade.service.BiPayService;
import com.spark.bipay.constant.CoinTransferType;
import com.spark.bipay.http.ResponseMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RequestController {
    @Autowired
    private BiPayService biPayService;

    /**
     * 发起转账请求
     */
    @PostMapping("/bipay/transfer")
    public ResponseMessage<String> transfer(@RequestBody TransferParam param) {
        CoinTransferType coinTransferType = CoinTransferType.unitOf(param.getUnit());
        if (coinTransferType == null){
            return ResponseMessage.error(BipayTransterEnum.UNKNOWN_COIN.getCode(),BipayTransterEnum.UNKNOWN_COIN.getMsg());
        }
        return biPayService.withdraw(param.getOrderId(), param.getAmount(), coinTransferType, param.getAddress(), param.getMemo());
    }

}
